package cn.zhz.cloud.auth.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.zhz.cloud.common.model.result.R;
import cn.zhz.cloud.auth.web.service.IUserService;
import cn.zhz.cloud.auth.web.model.dto.UserQueryDto;
import cn.zhz.cloud.auth.web.model.dto.UserSaveDto;
import cn.zhz.cloud.auth.web.model.vo.UserVo;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 用户 Controller
 * @author zhz
 * @since 2022-11-08
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Api(tags = "用户 接口集合")
public class UserController {

    private final IUserService iUserService;


    @ApiOperation(value = "分页查询", notes = "")
    @GetMapping(value = "/page")
    public R<Page<UserVo>> page(UserQueryDto queryDto) {
        return R.ok(iUserService.page(queryDto));
    }

    @ApiOperation(value = "详情", notes = "")
    @GetMapping(value = "/info/{id}")
    public R<UserVo> info(@Valid @NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        return R.ok(iUserService.info(id));
    }

    @ApiOperation(value = "保存", notes = "新增&&修改")
    @PostMapping(value = "/save")
    public R<String> save(@Valid @RequestBody UserSaveDto saveDto) {
        return R.ok(String.valueOf(iUserService.save(saveDto)));
    }

    @ApiOperation(value = "删除", notes = "")
    @PostMapping(value = "/delete/{id}")
    public R<Void> delete(@Valid @NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        iUserService.delete(id);
        return R.ok();
    }

}
